﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Database;
using Business;

namespace DT5_Anh09110006_Hung09110044_Vu09110157.QuanLy
{
    public partial class QuanLyHocVien : System.Web.UI.Page
    {
        Business.QuanLyHocVien qlhocvien = new Business.QuanLyHocVien();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loaddulieu();

            }
        }
        private void loaddulieu()
        {
             grvQLHocVien.DataSource = qlhocvien.LayDanhSachHocVien();
             grvQLHocVien.DataBind();
        }

        protected void grvQLHocVien_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName.Equals("ChiTiet"))
            {
                Session["MaHocVien"] = e.CommandArgument;
                Response.Redirect("ChiTietHocVien.aspx");
            }
            if (e.CommandName.Equals("Sua"))
            {
                Session["MaHocVien"] = e.CommandArgument;
                Response.Redirect("SuaHocVien.aspx");
            }
            if (e.CommandName.Equals("Xoa"))
            {
                if (qlhocvien.XoaHocVien(e.CommandArgument.ToString()))
                {
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectMe", "alert('Không thể xóa học viên này');", true);
                }
                loaddulieu();
            }

        }

        protected void grvQLHocVien_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grvQLHocVien.PageIndex = e.NewPageIndex;
            loaddulieu();

        }

        protected void btnThemHV_Click(object sender, EventArgs e)
        {
            Response.Redirect("ThemHocVien.aspx");
        }
    }
}